package com.cskaoyan.order.biz.handler;


import com.cskaoyan.order.biz.context.CreateOrderContext;
import com.cskaoyan.order.biz.context.TransHandlerContext;
import com.cskaoyan.order.feign.ShoppingFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class ClearCartItemHandler extends AbstractTransHandler {
    @Autowired
    ShoppingFeign shoppingFeign;

    //是否采用异步方式执行 不用做
    @Override
    public boolean isAsync() {
            return false;
        }

        @Override
        public boolean handle(TransHandlerContext context) {
            CreateOrderContext createOrderContext = (CreateOrderContext) context;
            Long userId = createOrderContext.getUserId();
            List<Long> productIds = createOrderContext.getBuyProductIds();
            for (Long productId : productIds) {
                shoppingFeign.deleteItem(userId, productId);
            }
        return true;
    }
}
